import { del, type R } from "@/api";
import { http } from "@/utils/http";

const path = "/api/v1/system/permission";
const customPath = "/api/v1/menu";

enum Index {
  listCustom = "/list",
  menuCustom = "/menu",
  allCustom = "/all",
  pageCustom = "/page",
  createCustom = "/create",
  editCustom = "/edit",
  editStatusCustom = "/edit/state"
}

export type PageResult = {
  total: number;
  current: number;
  size: number;
  records: Array<Record>;
};

export type Record = {
  menuType: number;
  parentId: number;
  title: string;
  name: string;
  path: string;
  component: string;
  rank: number;
  redirect: string;
  icon: string;
  extraIcon: string;
  enterTransition: string;
  leaveTransition: string;
  activePath: string;
  auths: string;
  frameSrc: string;
  frameLoading: boolean;
  keepAlive: boolean;
  hiddenTag: boolean;
  showLink: boolean;
  showParent: boolean;
};

export type ListResult = Array<Record>;

export type ListMenuIdCustomRecord = Array<string>;

export const apiDel = (id?: string) => {
  return del(path, id);
};

export const pageCustom = (data?: object) =>
  http.post<R<PageResult>, {}>(`${customPath}${Index.pageCustom}`, {
    data: data
  });

export const listCustom = (data?: object) =>
  http.post<R<ListResult>, {}>(`${customPath}${Index.listCustom}`, {
    data: data
  });

export const createCustom = (data?: object) =>
  http.post<R, {}>(`${customPath}${Index.createCustom}`, { data: data });

export const editCustom = (data?: object) =>
  http.post<R, {}>(`${customPath}${Index.editCustom}`, { data: data });

export const editStatusCustom = (data?: object) =>
  http.put(`${customPath}${Index.editStatusCustom}`, { data: data });

export const menuIdCustom = (id: string) =>
  http.get<R<ListMenuIdCustomRecord>, {}>(
    `${customPath}${Index.menuCustom}/${id}`
  );
